Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 603 - Parking lot / 603.cpp
blobc31475e7a5aa425ce4f7e8a03f1ef723130002c9
1 /*
2 Problema: E Parking lot
4 Equipo No. 3
6 Sebastían Arcila - Andrés Mejía
7 */
8 #include <iostream>
9 #include <fstream>
10 #include <map>
11 #include <string>
12 #include <iterator>
13 #include <vector>
14 #include <sstream>
16 using namespace std;
18 struct carro{
19 int id, donde;
20 bool parked;
21 carro(int ID, int Donde, bool Parked){
22 id = ID;
23 donde = Donde;
24 parked = Parked;
28 int main(){
29 int casos;
30 //fstream cin("parking.in");
31 cin >> casos;
32 //cout << "Lei casos: " << casos << endl;
33 bool primerCaso = true;
35 while (casos--){
36 vector<carro> carros;
37 if (!primerCaso) cout << endl;
38 primerCaso = false;
39 int id;
40 while (cin >> id && id != 99){
41 //cout << "Lei id: " << id << endl;
42 carros.push_back(carro(id, id, false));
45 /*cout << "Voy a imprimir carros:" << endl;
46 for (int i=0; i<carros.size(); ++i){
47 cout << carros[i].id << "-"<<carros[i].donde<<endl;
48 }*/
50 string line;
51 getline(cin, line);
52 while (getline(cin, line) && line != ""){
53 stringstream ss(line);
54 int salio;
55 ss >> salio;
56 //cout << "Lei salio: " << salio << endl;
58 int posClosest = 9999;
59 int minDistance = 9999;
60 for (int i=0; i<carros.size(); ++i){
61 int d;
62 if (!carros[i].parked){
64 if (carros[i].donde <= salio){
65 d = salio - carros[i].donde;
66 }else{
67 d = (salio+20) - carros[i].donde;
69 if (d < minDistance){
70 minDistance = d;
71 posClosest = i;
75 //cout << "minDistance es " << minDistance << endl;
76 //cout << "PosClosest es " << posClosest << endl;
77 if (posClosest == 9999) continue;
78 carros[posClosest].parked = true;
79 carros[posClosest].donde = salio;
81 for (int i=0; i<carros.size(); ++i){
82 if (!carros[i].parked){
83 int d = carros[i].donde + minDistance;
84 while (d > 20) d -= 20;
85 carros[i].donde = d;
89 /*cout << "Voy a imprimir carros:" << endl;
90 for (int i=0; i<carros.size(); ++i){
91 cout << carros[i].id << "-"<<carros[i].donde<<endl;
92 }*/
94 for (int i=0; i<carros.size(); ++i){
95 cout << "Original position " << carros[i].id << " ";
96 if (carros[i].parked){
97 cout << "parked in " << carros[i].donde << endl;
98 }else{
99 cout << "did not park" << endl;
103 return 0;